using Vin.Tool.AspNetCore.Singleton;

namespace Vin.Extension.Win32.Command.Node;

public class NodeData
{
    /// <summary>
    /// 节点Id
    /// </summary>
    public string Id { get; set; } = Guid.NewGuid().ToString();

    /// <summary>
    /// 程序集名称
    /// </summary>
    public string? AssemblyName { get; set; }

    /// <summary>
    /// 命名空间
    /// </summary>
    public string? NameSpace { get; set; }

    /// <summary>
    /// 类名
    /// </summary>
    public string ClassName { get; set; } = null!;

    public Type NodeType => System.Type.GetType($"{NameSpace ?? AssemblyName}.{ClassName}, {AssemblyName}") ??
                            throw new Exception("Command type is null");

    public INode Node => VinApp.GetRequiredServiceByHttpContext(NodeType) as INode ??
                         throw new Exception($"未找到节点类型{NodeType}");
}